package com.atguigu.aiproject.controller.ai;

import com.atguigu.aiproject.entity.Result;
import com.atguigu.aiproject.service.ImgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ai/image")
public class ImageController {
    
    @Autowired
    private ImgService imgService;

    @GetMapping("/models-list")
    public Result<List<String>> modelsList() {
        return Result.success(imgService.getModelsList());
    }

    /**
     * 获取图片，可以多张
     * 返回值json数据中存有taskId，用于查询图片是否生成完成
     * 获取完成的图片，需要调用/ai/image/imgstatus接口查询图片是否生成完成，生成完成返回图片地址，未完成返回null
     */
    @PostMapping("/create2")
    public Result<String> image(@RequestParam String ask,
                           @RequestParam(value = "num", defaultValue = "1") int num) {
        return Result.success(imgService.createImages(ask, num));
    }

    @GetMapping("/imgstatus")
    public Result<List<String>> isFinish(@RequestParam String taskId) {
        return Result.success(imgService.getImageStatus(taskId));
    }

    /**
     * 获取图片，只能一张
     */
    @PostMapping("/create")
    public Result<String> image(String ask) {
        return Result.success(imgService.createSingleImage(ask));
    }
}